.text

SETUPSECS = 4 

BOOTSEG = 0x7C0 

INITSEG = 0x9000

SETUPSEG = 0x9020

SYSSEG = 0x1000

ROOT_DEV = 0
SWAP_DEV = 0



entry _main

_main:
	mov ax, #BOOTSEG  
	mov ds, ax
	mov ax, #INITSEG
	mov es, ax
	mov cx, #256
	sub si, si
	sub di, di
	cld
	rep
	movsw				! copy to 0x9000
	jmpi boot, INITSEG

boot:
	mov ax, cs			! jmpi make cs = 0x9000
	mov es, ax
	mov ds, ax
	mov ss, ax			! ax = 0x9000 = es = ds = ss

	mov dx, #0x4000-12	! now reset paramenter tables
	mov sp, dx			! set dx = sp = 0x4000 - 12
	
	push #0				! carefull, and if you will know what is 'fs'
	pop fs				! fs = 0
	mov bx, #0x78
	seg fs
	lgs si, (bx)		! gs:si is sourse,		gs = parameter table segment si = fs:[0x78] = 0:[0x78]
	mov di, dx			! es:di is destination, di = 0x4000 - 12,			 es = 0x9000
	mov cx, #6			! copy 12 bytes
	cld					! 
	
	rep					
	seg gs				! 
	movsw				! copy gs:si to es:di

	mov di, dx			
	movb 4(di),*18
	
	seg fs
	mov (bx), di
	seg fs
	mov 2(bx),es		! set 0x78 = 0x4000 - 12 and 0x80 = 0x9000

	mov ax, cs
	mov fs, ax			
	mov gs, ax			! fs = gs = ax = 0x9000

	xor ah, ah
	xor dl, dl
	int 0x13			! reset disk

label2:
	call print_msg
	jmp label2

print_msg:

	mov ah,#0x03
	xor bh, bh
	int 0x10
	mov cx, #29
	mov bx, #0x0007
	mov bp, #msg
	mov ax, #0x1301

	int 0x10
	ret


print_hex_ax:

	mov cx, #4
	mov dx, (bp)

print_digit:

	rol dx, #4
	mov ah, #0xe
	mov al, dl
	and al, #0xf
	add al, #'0
	cmp al, #'9
	jbe good_digit
	add al, #'A - '0 - 10

good_digit:
	
	int 0x10
	loop print_digit
	ret

msg:
	.byte 13, 10
	.ascii "now, I'm in 0x9000 and I reset parameter table!"
	.byte 13, 10

.org 510
	.word 0xAA55


